package com.xinghen.common.plugin;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.internal.DefaultCommentGenerator;
import org.mybatis.generator.internal.util.StringUtility;

/**
 * @author xinghen
 * @ClassName: CommentGenerator
 * @Package: com.xinghen.common.plugin
 * @Description generator生成的代码去掉无用注释
 * @create 2017-12-06 10:53
 */
public class CommentGenerator extends DefaultCommentGenerator {

    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
        String remarks = introspectedColumn.getRemarks();
        if (StringUtility.stringHasValue(remarks)) {
            field.addJavaDocLine("/**");

            String[] remarkLines = remarks.split(System.getProperty("line.separator"));
            for (int index = 0, len = remarkLines.length; index < len; ++index) {
                String remarkLine = remarkLines[index];
                field.addJavaDocLine(" *   " + remarkLine);
            }

            this.addJavadocTag(field, false);

            field.addJavaDocLine(" */");
        }

    }
}
